﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using 请求响应加密.DAL;
using 请求响应加密.Models.SqlSugarDemo;

namespace 请求响应加密.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DynamicController : ControllerBase
    {
        private IRepository repository;

        public DynamicController(IRepository repository)
        {
            this.repository = repository;
        }


        [HttpGet]
        [Route("GetWorkingList")]
        public IActionResult GetWorkingList(string dynamicQuery)
        {
            repository.ChangeConnection("SugarPMS");

            #region 二级动态查询条件构建（大小写敏感，前端构建时需要注意）
            /*
                [ 
                    {"FieldName": "id","FieldValue": "1","ConditionalType": 10},
                    {"FieldName": "id","FieldValue": null,"ConditionalType": 12},
                    {
                        "ConditionalList": [{
                            "Key": 1,
                            "Value": {
                                "FieldName": "id",
                                "FieldValue": "2",
                                "ConditionalType": 0
                            }
                        }, {
                            "Key": 0,
                            "Value": {
                                "FieldName": "id",
                                "FieldValue": "2",
                                "ConditionalType": 0
                            }
                        }]
                    }
                ]
             */
            List<IConditionalModel> conditionalModels = repository.Utilities.JsonToConditionalModels(dynamicQuery);

            //ConditionalTree tree1 = new ConditionalTree();
            //tree1.ConditionalList = new List<KeyValuePair<WhereType, IConditionalModel>>()
            //{
            //    new KeyValuePair<WhereType, IConditionalModel>(WhereType.And,new ConditionalModel()
            //    {
            //        FieldName = "StartTime",
            //        ConditionalType = ConditionalType.Range,
            //        FieldValue = "2023-01-01,2024-12-27"
            //    })
            //};
            //conditionalModels.Add(tree1);
            #endregion
            //ISugarQueryable<Student> query = repository.Queryable<Student>().Where(conditionalModels);  
            //List<Student> workings = query.ToList();
            return Ok(null);
        }
    }
}
